package go.mybatis.daoimpl;

import go.mybatis.dao.UserDao;
import go.mybatis.pojo.User;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

/**
 * Created by shehuilong on 2018/5/4.
 */
public class UserDaoImpl implements UserDao {
    private SqlSession sqlSession;

    public UserDaoImpl(SqlSession sqlSession) {
        this.sqlSession = sqlSession;
    }

    @Override
    public User queryById(Long id) {
        return sqlSession.selectOne("UserDaoMapper.queryById",id);
    }

    @Override
    public List<User> queryBy() {
        return sqlSession.selectList("UserDaoMapper.queryBy");
    }

    @Override
    public void insertUser(User user) {
        sqlSession.insert("UserDaoMapper.insertUser",user);
        this.sqlSession.commit();
    }

    @Override
    public void updataUser(User user) {
        sqlSession.update("UserDaoMapper.updateUser",user);
        this.sqlSession.commit();
    }

    @Override
    public void deleteById(Long id) {
        sqlSession.delete("UserDaoMapper.deleteUser",id);
        this.sqlSession.commit();
    }
}
